/*************************************************
 *FileName:      circlefriends.js
 *Description:   朋友圈.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.003,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: true           //是否启用回弹 默认true
    });
    /*
     * 变量初始化
     */
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token;
    var page = 1;
    var page_num = 4;
    var article_id = '';
    var black_uid = '';
    var isUp = true;
    var commentobj,orderopen=true;
    var odata={ uid: uid,token :token};
    var olikeurl = "/index.php/api/article/articleLikeAdd";
    var odislikeurl = "/index.php/api/article/articleLikeCancel",msg;
    var touid,delectthis;
    /*
     * 主程序
     */ 
    window.addEventListener('circlefriends', function(e){//执行刷新
        mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,10);
        $('.main').html('');
        var opage = page;
        isUp = true;
        page = 1;
        getArticlesList();
        newmsg();
    });
    
    mui.init({
        beforeback: function() {
            var list = plus.webview.currentWebview().opener();
            mui.fire(list, 'refreshindex');
            return true;
        }
    });
    
    mui.plusReady(function(){ 
        var wv=plus.webview.currentWebview();// 关闭侧滑返回功能
        wv.setStyle({'popGesture':'none'});
        var old_back = mui.back;
        mui.back = function() {
            if(orderopen==true){
                old_back();
            }else{
                orderopen=true;
                $('#video')[0].pause();
                $('.pls-img-look').css({display:'none'});
            }
        }
    });
    
    $(document).ready(function() 
    {
        //样式加载
        pagecss();
    });
    /**
     * pagecss
     * 样式加载
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function pagecss(){
        localStorage.replace_myimg ? $('.title-bg').css('background-image','url('+DOMAIN_NAME+localStorage.replace_myimg+')'):$('.title-bg').css('background-image','url(images/fd_bj.png)');
        $('.my-img').attr('src',DOMAIN_NAME+localStorage.replace_face);
        $('.my-name').html(localStorage.replace_nickname);
        mui.plusReady(getArticlesList)
        mui.plusReady(newmsg)
//      getArticlesList();
//      newmsg();
        $('.circlefriends #myfriends').on('tap',function(){
            common.pageTransition('myfriends.html?friend_uid='+uid)
        })//朋友圈点击相机
        
        $('.circlefriends .camera').on('tap',function(){
            $('.popover').fadeIn();
            $('.table-view3').fadeIn();
        })//朋友圈点击相机
        
        $('.main').on('tap','.user-link-a-like',function(){
            article_id = $(this).attr('data-id');
            var obj = $(this);
            if(!$(this).hasClass('user-link-a-onlike')){
                lickclick(olikeurl,article_id,obj,1);
            }else{
                lickclick(odislikeurl,article_id,obj,2);
            }
            return false;
        })//点赞
        
                
        $('body').on('tap','.newmsg-box',function(){
            common.pageTransition('newmsg.html')
        })//朋友圈投诉
        
        $('.main').on('tap','.user-link-menu',function(){
            black_uid = $(this).attr('data-uid');
            article_id = $(this).parents('.pyq_list').attr('data-id');
            $('.popover').fadeIn();
            if(black_uid != uid){
                $('.table-view1').fadeIn();//他人
            }else{
                delectthis = $(this).parents('.pyq_list');
                $('.table-view0').fadeIn();//自己
            }
            return false;
        })//朋友圈投诉
        $('.circlefriends .table-view-delet').on('tap',function(){
            $('.table-view').css({display:'none'}); 
            mui.confirm('确定要删除这条朋友圈?','<div class="promit-msg">提示</div>',['确定','取消'],function(e){ 
                e.index ? $('.popover').css({display:'none'}):$('.popover').css({display:'none'})
                if(e.index == 0){
                    $.ajax({
                        type: "post",
                        url: DOMAIN_NAME + "/index.php/api/article/articleDel",
                        dataType:'jsonp',
                        data: { uid: uid, token: token, article_id: article_id },
                        success: function(data) {
                            if(data.error_code == 0){
                                mui.toast('删除成功！',{ duration:2000, type:'div' });
                                delectthis.remove();
                            }else if(data.error_code == 1001){
                                setTimeout(function(){
                                    exitlogin();
                                },1000);
                            }else{
                                mui.toast('删除失败！',{ duration:2000, type:'div' });
                            }
                        }
                    }); 
                }
            },'div');
        })//删除朋友圈
        
        $('.dialogue-btn').on('tap',function(){
            var otext =$(".dialogue-input").html();
            upcenter(otext);
        })//发送文字
        
        
        $('.circlefriends .table-view-jb').on('tap',function(){
            $('.table-view1').fadeOut();
            $('.table-view2').fadeIn();
        })//朋友圈举报
        
        $('.circlefriends .table-view-cell-pbpyq').on('tap',function(){
            $('.table-view').fadeOut();
            blackAdd();
        })//朋友圈屏蔽朋友圈

        $('.black').on('tap',function(){
            $('.menu-click1').css('display','none');
            black_uid = $(this).parent().attr('data-uid');
            blackAdd();
        })
        
        $('.main').on('tap','.list-text .list-img .img',function(){
            orderopen=false;
            var oindex =$(this).index();
            $('.pls-img-look').fadeIn();
            $('.dialogue ').css({display:'none'})
            if($(this).hasClass('user-img-video')){
                var imgs = '<div class="mui-slider-item"><a href="javascript:"><div id="vdo-loding"></div><video id="video" src="'+$(this).siblings('img').attr('data-url')+'"></video></div>';
            }else{
                var imgs = '',oli = '';
                $(this).parent().children('img').each(function(){
                    imgs += '<div class="mui-slider-item"><a href="javascript:"><img src="'+$(this).attr("data-url")+'"/></a></div>';
                    oindex ==$(this).index() ? oli+='<div class="mui-indicator mui-active"></div>': oli+='<div class="mui-indicator"></div>';
                })
            }
            $('.pls-img-look .mui-slider-group').html(imgs);
            if($(this).hasClass('user-img-video')){
                $('#video')[0].play();
                $('#video')[0].addEventListener('canplay',function(){//监听是否加载完毕
                    $('#vdo-loding').remove();
                })
                $('.mui-slider-indicator').html('');
            }else{
                $('.pls-img-look .mui-slider-indicator').html(oli);
            }
            mui('#plsslider').slider({interval:0,scrollTime: 0}).gotoItem(oindex);//跳转到第index张图片，index从0开始；
            return false;
        })//朋友圈图片显示
        
        $('.circlefriends').on('tap','.face-bot a',function(){
            //获得slider插件对象
            $('.menu-face .mui-slider').removeClass('active');
            $(this).addClass('face-bot-color').siblings().removeClass('face-bot-color');
            var oindex = $(this).index();
            if(oindex){
                $('.mui-slider-myface').addClass('active');
            }else{
                $('.mui-slider-sitface').addClass('active');
            }
        })
        
        $('.circlefriends').on('tap','.face-bq',function(){
             $('.chat-val').blur();
            var othisimg = $(this).attr("src");
            $('.chat-val').append('<img class="face-bq" src="'+othisimg+'">')
            $('.rests').css({display:'none'});
            $('.footer .bth').css({display:'block'});
            $('.dialogue-input').removeClass('dialogues');
            $('.chat-val-box').scrollTop($('.chat-val').height()) //到底
        })
        
        $('.circlefriends').on('tap','.menu-face .face-img',function(){
            var oul ='<img class="face-img" data-src="'+$(this).attr('data-src')+'" src="'+$(this).attr('src')+'">' ;
            upcenter(oul);
        })//发表情
        
        $('.circlefriends').on('tap','.face',function(){
            if(!$(this).hasClass('active')){
                $('.chat-val').blur();
                getface(0,'');
                getface(1,odata);
                $('.menu-box').css({display:'block'});
            }else{
                $('.chat-val').fadeIn();
                $('.menu-box').css({display:'none'});
            }
            $(this).toggleClass('active');
        })//表情等等点击上下
        
        $('body').on('focusin','.chat-val',function(){
            if($('.face').hasClass('active')){
                $('.menu-box').css({display:'none'});
                $('.face').toggleClass('active');
            }
        }).on('input','.chat-val',function(){
            var param = $(this).text();
            var regRule = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g;
            if(param.match(regRule)) {
                param = param.replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, "");
                $(this).text(param)
            }
            if($(this).text().length>0||$(this).find('.face-bq').length>0){
                $(this).removeClass('dialogues');
            }else{
                $(this).addClass('dialogues');
            }
        });
        
        $('body').on('tap','.pls-img-look',function(){
            $(this).css({display:'none'});
            orderopen=true;
            $('#video')[0].pause();
            
        })//朋友圈图片预览点击图片头部底部消失
        
        $('.popover-img').on('touchend',function(){
            $('.menu-click').fadeOut();
            $(this).css({display:'none'});
        })//朋友圈图片预览点击图片头部底部消失
        
        $('.myfriends .popover').on('touchend',function(){
            $('.menu-click').css({display:'none'});
            $(this).css({display:'none'});
        })//朋友圈点击头部底部消失
        
        $('.header-menu').on('tap',function(){
            if($(this).attr('data-uid') == uid){
                $('.menu-click2').fadeIn();//自己图片显示
            }else{
                $('.menu-click1').fadeIn();//他人的图片预览显示
            }
            $('.popover-img').css({display:'block'});
        })//朋友圈菜单显示

        $('.complain').on('tap',function(){
            black_uid = $(this).parent().attr('data-id');
            $('.menu-click').css({display:'none'});
            $('.table-view2').fadeIn();
        })//举报

        $('.save-this').on('tap',function(){
            var src = $('#slider').find('.mui-active').children('a').children('img').attr('src');
            if(!src){
                src = $('#slider .mui-slider-item').eq(0).children('a').children('img').attr('src');
            }
            plus.nativeUI.showWaiting('Downloading');
            var url = src;//下载链接
            var options = {
                method: "GET",//get传输方式
                filename: '_doc/'//文件保存位置
            };
            var dtask = plus.downloader.createDownload(src, {}, function(download, status) {
                if ( status == 200 ) { 
                    plus.nativeUI.closeWaiting();
                    plus.gallery.save(download.filename, function() {
                        mui.toast('Save successfully');
                    });
                } else {
                    alert( "Download failed: " + status ); 
                }
            });
            dtask.start();
        })//保存图片

        $('.delect-this').on('tap',function(){
            $('.menu-click3').css({display:'none'});
            $('.popover-img').css({display:'none'});
            var article_id = $(this).parent().attr('data-id');
            mui.confirm('确定要删除这条朋友圈吗？','提示',['确定','取消'],function(e){
                if(e.index == 0){
                    $.ajax({
                        type: "post",
                        url: DOMAIN_NAME + "/index.php/api/article/articleDel",
                        dataType:'jsonp',
                        data: { uid: uid, token: token, article_id: article_id },
                        success: function(data) {
                            if(data.error_code == 0){
                                $('.menu-click').fadeOut();
                                $('.main').find('.pyq_list[data-id="'+article_id+'"]').remove();
                                mui.toast('删除成功！',{ duration:2000, type:'div' });
                            }else if(data.error_code == 1001){
                                setTimeout(function(){
                                    exitlogin();
                                },1000);
                            }else{
                                mui.toast('删除失败！',{ duration:2000, type:'div' });
                            }
                        }
                    }); 
                }
            },'div');
        })//删除动态
        
        $('.circlefriends').on('tap','.table-view2 .table-select',function(){
            $(this).toggleClass('active');
        })
        
        $('.main').on('tap','.like-box .mui-icon',function(){
            if($(this).attr('class')=='mui-icon mui-icon-arrowup'){
                $(this).parents('li').find('.like-talking').hide();
                $(this).removeClass('mui-icon-arrowup').addClass('mui-icon-arrowdown');
                $(this).parents('.like-box').css({height:'2rem'});
            }else{
                $(this).parents('li').find('.like-talking').show();
                $(this).removeClass('mui-icon-arrowdown').addClass('mui-icon-arrowup');
                $(this).parents('.like-box').css({height:'auto'});
            }
        })//朋友圈下拉框
        //
        
        $('.circlefriends .popover-img').on('tap',function(){
            $('.circlefriends .footer').css({'display': 'none'});
            $(this).css({'display': 'none'});
            $('.dialogue .dialogue-input').blur();
        })//朋友圈失焦
        
        $('.main').on('tap','.user-link-a-comment',function(){
            $('.dialogue-input').addClass('dialogues')
            msg='';
            touid ="";
            $('.dialogue-input').addClass('dialogues').attr('data-content', '请输入文字...');
            article_id = $(this).parents('li').attr('data-id');
            commentobj=$(this).parents('li').find('.like-talking');
            $('.dialogue').css({'display': 'block'});
            $('.mui-scroll').on('touchend',function(){
                $('.dialogue-input').text('');
                $('.dialogue').css({'display': 'none'});
                $('.dialogue .dialogue-input').blur();
            })
            return false;
        })//朋友圈评论
        
        $('.main').on('tap','.talktext',function(){
            touid =$(this).parents('.like-talk').attr('data-uid') ;
            article_id = $(this).parents('li').attr('data-id');
            msg=$(this).find('.talkname i').text();
            if(touid==uid){
                mui.alert('不能评论自己！','提示','确定',null,'div')
                return false;
            }
            $('.dialogue-input').addClass('dialogues').attr('data-content', '回复'+msg);
            commentobj=$(this).parents('li').find('.like-talking');
            $('.dialogue').css({'display': 'block'});
            $('.mui-scroll').on('touchend',function(){
                $('.dialogue').css({'display': 'none'});
                $('.dialogue .dialogue-input').blur();
            })
            return false;
        })//朋友圈评论
        
        
        $('.main').on('tap','.showall',function(){
            if($(this).text()=='显示全文'){
                $(this).text('收起全文');
                $(this).prev().css({'-webkit-line-clamp':'inherit'});
            }else{
                $(this).text('显示全文');
                $(this).prev().css({'-webkit-line-clamp':'3'});
            }
            return false;
        })//朋友圈收起全文
        
        $('.main').on('tap','.list-text',function(){
            var id = $(this).parents('li').attr('data-id');
            if(!$(this).parents('li').attr('data-adm-url')){
                common.pageTransition('particulars.html?id='+id);
            }else{
                plus.runtime.openURL($(this).parents('li').attr('data-adm-url'));
            }
        })//详情跳转
    }

 
     /**
     * blackAdd
     * 屏蔽朋友圈
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function blackAdd(){
        mui.confirm('确定要屏蔽她的朋友圈?','<div class="promit-msg">提示</div>',['确定','取消'],function(e){
            $('.popover').fadeOut();
            if(e.index == 0){
                if(uid == black_uid){
                    mui.toast('您不能屏蔽自己！',{ duration:2000, type:'div' });
                    black_uid = ''; 
                }else{
                    $.ajax({
                        type: "post",
                        url: DOMAIN_NAME + "/index.php/api/user/blacklistAdd",
                        dataType:'jsonp',
                        data: { uid: uid, token: token, black_uid: black_uid },
                        success: function(data) {
                            if(data.error_code == 0){
                                mui.toast('屏蔽成功！',{ duration:2000, type:'div' });
                                $('.main > li').each(function(){
                                    if($(this).attr('data-uid') == black_uid){
                                        $(this).remove();
                                    }
                                })
                                black_uid = '';
                            }else if(data.error_code == 1001){
                                setTimeout(function(){
                                    exitlogin();
                                },1000);
                            }else{
                                mui.toast(data.error_msg,{ duration:2000, type:'div' });
                                black_uid = '';
                            }
                        }
                    }); 
                }
            }
        },'div');
    }
    var listar,liend;
    function getArticlesList(){
        listar=$('.main li').length;
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/article/articlesList",
            dataType:'jsonp',
            data: { uid: uid, token: token, page: page, page_num: page_num },
            success: function(data) {
                if(data.error_code == 0){
                    console.log(data)
                    liend=data.data.length+listar;
                    var articles = '';
                    if(data.data.length == page_num){
                        $('.mui-scroll').children('.ys-scroll-btm').html('上拉加载更多');
                        isUp = true;
                    }else{
                        $('.mui-scroll').children('.ys-scroll-btm').html('已经到底了');
                        isUp = false;
                    }
                    $('.mui-scroll').children('.ys-scroll-top').html('下拉刷新数据').attr('style', false);
                    for(var i=0; i<data.data.length; i++){
                        var article_files = ''
                        var likes_heads = ''
                        var comment_content = '';
                        var is_like = '';
                        var like = data.data[i].is_like;
                        var like_nums = data.data[i].like_nums;
                        var comments_nums = data.data[i].comment_nums;
                        var type = '';
                        if($('.main').find('.pyq_list[data-id="'+data.data[i].id+'"]').html()){
                            console.log(data.data[i].id);
                        }else{
                            if(data.data[i].files){
                                if(data.data[i].files.length==1){
                                    if(data.data[i].files[0].type == 1){
                                        article_files += '<img class="img" src="'+DOMAIN_NAME+data.data[i].files[0].thumb+'" data-url="'+DOMAIN_NAME+data.data[i].files[0].url+'"/>';
                                        type = 'user-img-big';
                                    }else{
                                        article_files += '<div class="user-img-video img"></div><img onerror="chatimgExists(this)" src="'+data.data[i].files[0].thumb+'" data-src="'+data.data[i].files[0].thumb+'" data-url="'+data.data[i].files[0].url+'"/>';
                                        type = 'user-img-big vdio-imgbox';
                                    }
                                }else{
                                    for(var j=0; j<data.data[i].files.length; j++){
                                        article_files += '<img class="img" src="'+DOMAIN_NAME+data.data[i].files[j].thumb+'" data-url="'+DOMAIN_NAME+data.data[i].files[j].url+'"/>';
                                        type = 'user-img-smo';
                                    }
                                }
                                
                            }
                            if(data.data[i].comments){
                                for(var j=0; j<data.data[i].comments.length; j++){
                                    var ocontent = data.data[i].comments[j].comment.replace(/\.\?\./g,"'");
                                    if(data.data[i].comments[j].to_uid=='0'){
                                        comment_content += '<div class="like-talk" data-uid="'+data.data[i].comments[j].uid+'">'
                                            +'<div class="like-img"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+data.data[i].comments[j].face+'"/></div>'
                                            +'<div class="talktext"><span class="talkname"><i>'+data.data[i].comments[j].nickname+'</i>： </span>'+ocontent+'</div></div>'
                                    }else{
                                        comment_content += '<div class="like-talk" data-uid="'+data.data[i].comments[j].uid+'">'
                                            +'<div class="like-img"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+data.data[i].comments[j].face+'"/></div>'
                                            +'<div class="talktext"><span class="talkname"><i>'+data.data[i].comments[j].nickname+'</i><em class="color">回复</em>'+data.data[i].comments[j].to_nickname+'： </span>'+ocontent+'</div></div>'
                                    }
                                        
                                }
                            }
                            if(data.data[i].likes){
                                for(var j=0; j<data.data[i].likes.length; j++){
                                    likes_heads += '<div class="like-img" data-likeuid="'+data.data[i].likes[j].uid+'"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+data.data[i].likes[j].face+'"/></div>';
                                }
                            }
                            if(data.data[i].is_like){
                                is_like = 'user-link-a-onlike';
                            }
                            if(data.data[i].type == 0){
                                articles += '<li class="pyq_list" data-id="'+data.data[i].id+'" data-isLike="'+like+'" data-uid="'+data.data[i].uid+'" data-likeNums="'+like_nums+'" data-commentNums="'+comments_nums+'"><div class="list">'
                                    +'<div class="user-img-box"><img class="user-img" onerror="imgExists(this)" src="'+DOMAIN_NAME+data.data[i].face+'"/></div>'
                                    +'<div class="list-text">'
                                    +'<div class="user-name">'+data.data[i].nickname+'</div>'
                                    +'<div class="user-text">'+data.data[i].content+'</div>'
                                    +'<div class="list-img '+type+'">'+article_files+'</div>'
                                    +'<div class="user-link">'
                                    +'<a class="user-link-a user-link-a-comment"><i class="comment">说点什么</i></a>'
                                    +'<a class="user-link-a user-link-a-like '+is_like+'" data-id="'+data.data[i].id+'"><i class="like">点赞</i></a>'
                                    +'<a class="user-link-menu" data-uid="'+data.data[i].uid+'"></a>'
                                    +'</div></div>'
                                    +'<div class="adm-box"><span class="time">'+common.formatPassTime(data.data[i].publish_time*1000)+'</span></div></div>'
                                    +'<div class="like-box"><a class="mui-icon mui-icon-arrowdown"></a>'+likes_heads+'</div>'
                                    +'<div class="like-talking" data-id="'+data.data[i].id+'">'+comment_content+'</div></li>' 
                            }else{
                                articles += '<li class="pyq_list" data-adm-url="'+data.data[i].url+'" data-id="'+data.data[i].id+'" data-isLike="'+like+'" data-uid="'+data.data[i].url+'" data-likeNums="'+like_nums+'" data-commentNums="'+comments_nums+'"><div class="list">'
                                    +'<div class="user-img-box"><img class="user-img" onerror="imgExists(this)"  src="'+DOMAIN_NAME+data.data[i].head_img+'"/></div>'
                                    +'<div class="list-text">'
                                    +'<div class="user-name">'+data.data[i].title+'</div>'
                                    +'<div class="user-text">'+data.data[i].content+'</div>'
                                    +'<div class="user-img-big-adm"><img src="'+DOMAIN_NAME+data.data[i].cover_img+'"/></div>'
                                    +'<div class="user-link">'
                                    +'<a class="user-link-a user-link-a-comment"><i class="comment">说点什么</i></a>'
                                    +'<a class="user-link-a user-link-a-like '+is_like+'" data-id="'+data.data[i].id+'"><i class="like">点赞</i></a>'
                                    +'</div></div>'
                                    +'<div class="adm-box"><span class="time">'+common.formatPassTime(data.data[i].publish_time*1000)+'</span>'
                                    +'<span class="adm">广告<em class="adm-em"></em></span></div></div>'
                                    +'<div class="like-box">'
                                    +'<a class="mui-icon mui-icon-arrowdown"></a>'
                                    +likes_heads+'</div><div class="like-talking" data-id="'+data.data[i].id+'">'+comment_content+'</div></li>'
                            }
                            
                        }
                    }
                    $('.main').append(articles);
                    page++;
                    for(var i=listar ; i<liend ; i++){
                        var obj=$('.main li').eq(i);
                        var o  = Math.round(obj.find('.user-text').height());
                        var s  = parseFloat(obj.find('.user-text').css('line-height'));
                        if(o/s>3){
                            obj.find('.user-text').css({'-webkit-line-clamp':'3'}).after('<button class="showall">显示全文</button>');
                        }
                    }
                    $('.vdio-imgbox img').on('load',function(){
                        if($(this).attr('src')=='images/vdo_loading.gif'){
                            vdolazing($(this));
                        }
                    })
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                    $('.mui-scroll').children('.ys-scroll-btm').html('已经到底了');
                    isUp = false;
                }
            }
        });
    }

    common.scrollUpDown($('.mui-scroll'),function(index){
        if(index>0&&isUp){
            isUp = false;
            getArticlesList();
        }else if(index<0){
            $('.main').html('');
            isUp = true;
            page = 1;
            newmsg();
            getArticlesList();
        }else if(index>0 && !isUp){
            $('.mui-scroll').children('.ys-scroll-btm').html('已经到底了');
        }
    });
     /**
     * upcenter
     * 发送评论
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function upcenter(oul){
        var cotent = oul.replace(/\"/g,".?.");
        common.loadingIn();
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/article_comment/commentadd",
            dataType:'jsonp',
            data: { uid: uid, token: token, article_id: article_id, comment: cotent ,to_uid:touid},
            success: function(data) {
                console.log(touid)
                common.loadingOut();
                if(data.error_code == 0){
                    if(msg==''){
                        var li = '<div class="like-talk" data-uid="'+uid+'">'
                        +'<div class="like-img"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+localStorage.replace_face+'"/></div>'
                        +'<div class="talktext"><span class="talkname"><i>'+localStorage.replace_nickname+'</i>：</span>'+oul+'</div>'
                        +'</div>';
                    }else{
                        var li = '<div class="like-talk" data-uid="'+uid+'">'
                        +'<div class="like-img"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+localStorage.replace_face+'"/></div>'
                        +'<div class="talktext"><span class="talkname"><i>'+localStorage.replace_nickname+'</i><em class="color">回复</em>'+msg+'：</span>'+oul+'</div>'
                        +'</div>';
                    }
                    commentobj.append(li);
                    $('.comment-nums').html($('.comment-nums').html()-0+1);
                    $(".dialogue-input").html('');
                    $(".dialogue-input").blur();
                    $('.dialogue').css({'display': 'none'});
                    $('.menu-box').css({display:'none'});
                    $('.face').toggleClass('active');
                    mui.toast('评论成功！',{ duration:2000, type:'div' });
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                    mui.toast(data.error_msg,{ duration:2000, type:'div' });
                }
            }
        }); 
    }
     /**
     * 
     * 菜单栏取消或确定
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    $('body').on('tap','.table-view-cell-cancel',function(){
        if($(this).hasClass('sure')){
            var report_content = [];
            var i = 0;
            $('.table-select').each(function(){
                if($(this).hasClass('active')){
                    report_content[i] = $(this).text();
                    i++;
                }
            })
            if(!report_content){
                mui.toast('请选择您要举报的内容！',{ duration:2000, type:'div' });
                return false;
            }
            $.ajax({
                type: "post",
                url: DOMAIN_NAME + "/index.php/api/report/reportAdd",
                dataType:'jsonp',
                data: { uid: uid, token: token, report_uid: black_uid, report_content: report_content, type: 1 ,article_id:article_id},
                success: function(data) {
                    if(data.error_code == 0){
                        mui.toast('举报成功！',{ duration:2000, type:'div' });
                    }else if(data.error_code == 1001){
                        setTimeout(function(){
                            exitlogin();
                        },1000);
                    }else{
                        mui.toast('举报失败！',{ duration:2000, type:'div' });
                    }
                }
            });

        }
        $('.table-select').removeClass('active');
        $('.popover').fadeOut();
        $('.table-view').fadeOut();
    })//下拉菜单栏取消
    /**
     * 
     * 朋友圈点赞
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function lickclick(url,article_id,obj,type){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + url,
            dataType:'jsonp',
            data: { uid: uid, token: token, article_id: article_id },
            success: function(data) {
                if(data.error_code == 0){
                    if(type==1){
                        $('.main').find('.pyq_list[data-id="'+article_id+'"]').attr('data-isLike','1');
                        obj.addClass('user-link-a-onlike'); 
                        obj.parents('li').find('.mui-icon').after('<div class="like-img" data-likeuid="'+uid+'"><img onerror="imgExists(this)" src="'+DOMAIN_NAME+localStorage.replace_face+'"/></div>');
                    }else if(type==2){
                        $('.main').find('.pyq_list[data-id="'+article_id+'"]').attr('data-isLike','0');
                        obj.removeClass('user-link-a-onlike');
                        obj.parents('li').find('.like-img[data-likeuid="'+uid+'"]').remove();
                    }
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                    (type==1)&&(type==3)?mui.toast('点赞失败！',{ duration:2000, type:'div' }):mui.toast('取消点赞失败！',{ duration:2000, type:'div' });
                }
            }
        }); 
    }


     /**
     * 
     * 获取表情
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function getface(sys,odata){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME +'/index.php/api/chat/getSystemExpressionsList' ,
            dataType:'jsonp',
            data: odata,
            success: function(data) {
                var ohtml='';
                var oli ='';
                if(data.error_code == 0){
                    ohtml+='<div class="mui-slider-group"><div class="mui-slider-item">';
                    for(var i=0 ; i<data.data.length; i++){
                        if(sys==0){
                            if((i%21==0)&&(i!=0)){
                                ohtml+='</div><div class="mui-slider-item">';
                                oli+='<div class="mui-indicator"></div>';
                            }
                            ohtml+='<a data-id="'+data.data[i].id+'"><img class="face-bq" src="'+DOMAIN_NAME+data.data[i].url+'"></a>';
                        }else{
                            if(((i+1)%10==0)&&(i!=0)){
                                ohtml+='</div><div class="mui-slider-item">';
                                oli+='<div class="mui-indicator"></div>';
                            }else if((i==0)&&(sys==1)){
                                ohtml+='<a class="face-add"><img src="images/chat_add.png"></a>';
                            }
                            ohtml+='<a data-id="'+data.data[i].id+'" ><img class="face-img" data-src="'+data.data[i].url+'"  data-thumb="'+data.data[i].url+'" src="'+DOMAIN_NAME+data.data[i].url+'"></a>';
                        }
                        
                    }
                    ohtml+='</div></div><div class="mui-slider-indicator"><div class="mui-indicator mui-active"></div>'+oli+'</div></div>';
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                    $('.menu-face .mui-slider').eq(sys).find('.mui-slider-group').html('');
                }
                sys==0? $('.mui-slider-sitface').html(ohtml): $('.mui-slider-myface').html(ohtml);
                mui(".mui-slider").slider({interval: 0});
            }
        });
    }
    //人物链接
    $('.main').on('tap','.user-img',function(){
        var otid = $(this).parents('li').attr('data-uid');
        if(!$(this).parents('li').attr('data-adm-url')){
            common.pageTransition('personal.html?friend_uid='+otid)
        }
        return false;
    })
    
    $('.main').on('tap','.pyq_list .like-img',function(){
        var otid = $(this).attr('data-likeuid');
        common.pageTransition('personal.html?friend_uid='+otid)
        return false;
    })
    
    $('.main').on('tap','.like-talking .like-img img',function(){
        var otid = $(this).parents('.like-talk').attr('data-uid');
        common.pageTransition('personal.html?friend_uid='+otid)
        return false;
    })
    
    
    function newmsg(){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/article_comment/getNewCommentNums",
            dataType:'jsonp',
            data: { uid: uid, token: token },
            success: function(data) {
                if(data.error_code == 0){
                    console.log(data)
                    $('.newmsg').css({display:'block'})
                    if(data.data.face){
                        $('.newmsg-img').attr('src',DOMAIN_NAME+data.data.face)
                    }else{
                        $('.newmsg-img').attr('src','images/myimg.jpg')
                    }
                    $('.newmsg-span').text(data.data.nums+'条新消息')
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                    $('.newmsg').css({display:'none'})
                }
            }
        });
    }
    /**
     * adds //方法名
     * @陈灿 //作者名
     * @DateTime 2018-01-010T0116:25:00+0800 //时间
     * @param    int    $goods_id //参数
     * @param    array  $data //参数
     * @return    array  [error_code, error_msg, goods_id] //返回值
     */

function vdolazing(obj){//视频加载
    setTimeout(function(){
        var ovdo_objsrc=obj.attr('data-src');
        obj.attr('src',ovdo_objsrc);
    },5000)
}